// 类型谓词
type Fish = {
    name: string
    swim: () => void
}

type Dog = {
    name: string
    run: () => void
}

function isFish(pet: Fish | Dog): pet is Fish {
    return (pet as Fish).swim() !== undefined
}

let pet: Fish = { name: 'fish', swim: () => { } }

console.log(isFish(pet))
